<?php
    $this->layout('base.phtml', [
        'title' => _('New link'),
        'canonical' => url_full('new link'),
        'current_page' => 'new link',
        'has_errors' => $form->isInvalid(),
        'modal_enabled' => true,
    ]);
?>

<div class="section">
    <div class="section__title">
        <h1 id="modal-title"><?= _('New link') ?></h1>
    </div>

    <form method="post" action="<?= url('create link') ?>">
        <?= $this->include('alerts/_error.phtml', ['message' => $form->error('@base')]) ?>

        <div class="form-group">
            <label for="url">
                <?= _('What’s the address of the link?') ?>
            </label>

            <?php if ($form->isInvalid('url')): ?>
                <p id="url-error" class="form-group__error">
                    <?= _('Error:') ?>
                    <?= $form->error('url') ?>
                </p>
            <?php endif; ?>

            <input
                id="url"
                name="url"
                type="url"
                placeholder="https://…"
                required
                value="<?= protect($form->url) ?>"
                autocomplete="off"
                autofocus
                aria-describedby="url-caption"
                <?php if ($form->isInvalid('url')): ?>
                    aria-errormessage="url-error"
                    aria-invalid="true"
                <?php endif; ?>
            />

            <p id="url-caption" class="form-group__caption">
                <?= _('It can be copy-paste from the <abbr>URL</abbr> bar, at the top of your browser.') ?>
            </p>
        </div>

        <fieldset aria-describedby="collections-desc">
            <legend><?= _('Collections') ?></legend>

            <?= $this->include('collections/_selector.phtml', [
                'form' => $form,
            ]) ?>
        </fieldset>

        <div class="form-group">
            <input
                type="checkbox"
                id="is-hidden"
                name="is_hidden"
                <?= $form->is_hidden ? 'checked' : '' ?>
            />

            <label class="label--checkbox" for="is-hidden">
                <?= _('Hide this link in public collections') ?>
            </label>
        </div>

        <div class="form-group">
            <input
                type="checkbox"
                id="read-later"
                name="read_later"
                <?= $form->read_later ? 'checked' : '' ?>
            />

            <label class="label--checkbox" for="read-later">
                <?= _('Mark to read later?') ?>
            </label>
        </div>

        <div class="form__actions">
            <button type="submit" class="button--primary">
                <?= _('Add the link') ?>
            </button>
        </div>

        <input type="hidden" name="csrf_token" value="<?= csrf_token($form) ?>" />
    </form>
</div>
